from rest_framework import serializers
from .models import AreaInfo


# 用于输出省，某个地区的子级地区
class AreaSerializer(serializers.ModelSerializer):
    class Meta:
        model = AreaInfo
        fields = ['id', 'name']


# 用于输出某个地区
class AreaSubSerializer(serializers.ModelSerializer):
    # 关系属性，需要指定read_only=True
    # 一个地区包含多个子级地区many=True
    subs = AreaSerializer(read_only=True, many=True)

    class Meta:
        model = AreaInfo
        fields = ['id', 'name', 'subs']
